var prefix = jsctx + "/acctTenantOperator";

var tenantOperatorAccountRecord = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        }, 10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 80;
    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listPageTenantOperatorAccountRecord",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    pageSize: 20,
                    pageList: [20],
                    pageNumber: 1,
                    sidePagination: "server",
                    paginationShowPageGo: true,
                    height: h,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            outTradeNo: $('#outTradeNo').val(),
                            tenantOperatorCode: $('#tenantOperatorCode').val(),
                            startTime: $('#startTime').val(),
                            endTime: $('#endTime').val()
                        };
                    },
                    columns: [
                        {
                            title: '#', field: '', width: '50', align: 'left',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'operatorName', title: '分销商名称', align: 'left', width: '150'},
                        {field: 'loginName', title: '分销商账号'},
                        {field: 'outTradeNo', title: '交易订单号'},
                        {
                            field: 'recordType', title: '变动类型', width: '100', align: 'left',
                            formatter: function (value, row, index) {
                                if (row.recordType == '0') {
                                    return '<span >收入</span>';
                                } else if (row.recordType == '1') {
                                    return '<span >支出</span>';
                                }
                            }
                        },
                        {field: 'amount', title: '变动金额'},
                        {field: 'result', title: '变动后余额'},
                        {field: 'createdTime', title: '变动时间'},

                    ]
                });
    }

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    function goBack() {
        location.href = prefix + "/index";
    }

    function exportTenantOperatorAccountRecord() {
        $.fileDownload(prefix + "/exportTenantOperatorAccountRecord", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                tenantOperatorCode: $("#tenantOperatorCode").val().trim(),
                outTradeNo: $("#outTradeNo").val().trim(),
                startTime: $("#startTime").val().trim(),
                endTime: $("#endTime").val().trim(),
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })
    }

    function acctBank(tenantOperatorCode) {
        location.href = prefix + "/acctBank/" + tenantOperatorCode;
    }

    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        acctBank: acctBank,
        exportTenantOperatorAccountRecord: exportTenantOperatorAccountRecord
    };
})();
